package com.dmy.common.exception;

import com.dmy.common.entity.ResultBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * create by huahuadelei for 2020/1/4
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    private final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    public ResultBean handerException(Exception ex){
        logger.error(ex.getMessage(),ex);
        if(ex instanceof ExinException){
            String code = ((ExinException) ex).getCode();
            return ResultBean.buildResult(code).msg(ex.getMessage());
        }else{

            return ResultBean.buildResult("500").msg(ex.getMessage());
        }
    }
}
